package com.qdsg.ysg.doctor.viewmodel

import android.view.View
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.rest.business.RestProxy
import com.rest.response.BaseResponse
import com.rest.response.CloudListResponse
import io.reactivex.Observer
import io.reactivex.disposables.Disposable
import jz.joyoung.robot.util.UtilList

class CloudListViewModel : ViewModel() {


    val list = mutableListOf<CloudListResponse.Cloud>()
    val dataChanged = MutableLiveData<Int>()
    val dataEmpty = MutableLiveData<Int>()


    fun getCloudList(flag: String) {
        RestProxy.getInstance().getCloudList(flag, object : Observer<CloudListResponse> {
            override fun onComplete() {
            }

            override fun onSubscribe(d: Disposable) {
            }

            override fun onNext(t: CloudListResponse) {
                if (!UtilList.isEmpty(t.data.records)) {
                    list.clear()
                    list.addAll(t.data.records)
                    dataChanged.value = dataChanged.value?.plus(1)
                } else {
                    dataEmpty.value = dataEmpty.value?.plus(1)
                }

            }

            override fun onError(e: Throwable) {
            }
        })

    }

    fun changeFlag(id: String, flag: String) {
        RestProxy.getInstance().changeFlag(id, flag, object : Observer<BaseResponse<*>> {
            override fun onComplete() {
            }

            override fun onSubscribe(d: Disposable) {

            }

            override fun onNext(t: BaseResponse<*>) {

            }

            override fun onError(e: Throwable) {
            }
        })
    }


}